#include <stdio.h>
#include <unistd.h>

int main(int argc, char const *argv[])
{
    char strBuffer[200] = {0};
    int iRet;

    iRet = readlink( "./05_slink", strBuffer, sizeof(strBuffer) );
    if( -1 == iRet )
    {
        perror( "fail readlink ./slink_05" );
        return -1;
    }

    printf( "symlink: %s\n", strBuffer );   //打印: " 05_symlink.c ", 即是这个symbolic link所指向的文件.

    // 函数 readlink 不能读取 hard link
    iRet = readlink( "./05_hlink", strBuffer, sizeof(strBuffer) );
    if( -1 == iRet )
    {
        perror( "fail readlink ./hlink_05" );    //将返回 Invalid argument 系统错误
        return -1;
    }

    printf( "hymlink: %s\n", strBuffer );

    return 0;
}

/*
函数功能:
    获取 symbolic link 所指向的文件名.
    
涉及函数:
    readlink 

知识要点:
    reaklink 只能读取 symbolic, 不能读取 hardlink 
    man 2 readlink
    <Linux程序设计>(第四版) page 100
*/